package com.base.library.manager;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.base.library.R;

/**
 * Created by ChengZhi on 2017/4/16.
 */

public class DialogManager {
    public static MaterialDialog showDefaultProgress(Context context) {
        return showProgress(context, R.string.being_processed, R.string.loading);
    }

    public static MaterialDialog showProgress(Context context, int title, int content) {
        return showProgress(context, context.getString(title), context.getString(content));
    }

    public static MaterialDialog showProgress(Context context, String title, String content) {
        return new MaterialDialog.Builder(context)
                .title(title)
                .content(content)
                .progress(true, 0)
                .progressIndeterminateStyle(false)
                .show();
    }

    public static AlertDialog showYesNoDialog(Context context, String text, String yes, String no, final DialogInterface.OnClickListener listener) {
        View view = LayoutInflater.from(context).inflate(R.layout.view_dialog_yes_no, null);
        TextView ss = (TextView) view.findViewById(R.id.dialogTv);
        ss.setText(text);
        final AlertDialog dialog = new AlertDialog.Builder(context).setCancelable(true).show();
        Window win = dialog.getWindow();
        win.setContentView(view);

        Button btnYes = (Button) view.findViewById(R.id.yesBtn);
        btnYes.setText(yes);
        btnYes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
                dialog.dismiss();
            }
        });
        Button btnNo = (Button) view.findViewById(R.id.noBtn);
        btnNo.setText(no);
        btnNo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
                dialog.dismiss();
            }
        });
        return dialog;
    }

    public static AlertDialog showYesDialog(Context context, String text, String yes, final DialogInterface.OnClickListener listener) {
        View view = LayoutInflater.from(context).inflate(R.layout.view_dialog_yes, null);
        TextView ss = (TextView) view.findViewById(R.id.dialogTv);
        ss.setText(text);
        final AlertDialog dialog = new AlertDialog.Builder(context).setCancelable(false).show();
        dialog.setCanceledOnTouchOutside(false);
        Window win = dialog.getWindow();
        win.setContentView(view);

        Button btnYes = (Button) view.findViewById(R.id.yesBtn);
        btnYes.setText(yes);
        btnYes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
                dialog.dismiss();
            }
        });

        return dialog;
    }

    public static AlertDialog showSetUpDialog(Context context, String text, String yes, final DialogInterface.OnClickListener listener) {
        View view = LayoutInflater.from(context).inflate(R.layout.view_dialog_set_up, null);
        TextView ss = (TextView) view.findViewById(R.id.dialogTv);
        ss.setText(text);
        final AlertDialog dialog = new AlertDialog.Builder(context).setCancelable(true).show();
        Window win = dialog.getWindow();
        win.setContentView(view);

        Button btnYes = (Button) view.findViewById(R.id.yesBtn);
        btnYes.setText(yes);
        btnYes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
                dialog.dismiss();
            }
        });
        return dialog;
    }
}
